package com.ejia.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.ejia.server.UserService;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.SystemColor;
import javax.swing.ImageIcon;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Toolkit;

public class XGMM extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					XGMM frame = new XGMM();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public XGMM() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(XGMM.class.getResource("/com/ejia/photo/客户管理系统.png")));
		setTitle("修改密码");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 728, 464);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("用户名");
		label.setFont(new Font("宋体", Font.PLAIN, 24));
		label.setBounds(119, 65, 81, 21);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("旧密码");
		label_1.setFont(new Font("宋体", Font.PLAIN, 24));
		label_1.setBounds(119, 144, 81, 21);
		contentPane.add(label_1);
		
		JLabel label_2 = new JLabel("新密码");
		label_2.setFont(new Font("宋体", Font.PLAIN, 24));
		label_2.setBounds(119, 230, 81, 21);
		contentPane.add(label_2);
		
		textField = new JTextField();
		textField.setFont(new Font("宋体", Font.PLAIN, 24));
		textField.setBounds(319, 62, 266, 27);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_1.setColumns(10);
		textField_1.setBounds(319, 141, 266, 27);
		contentPane.add(textField_1);
		
		textField_2 = new JTextField();
		textField_2.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_2.setColumns(10);
		textField_2.setBounds(319, 227, 266, 27);
		contentPane.add(textField_2);
		
		JButton button = new JButton("修改");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			String name=textField.getText();
			String pwd1=textField_1.getText();
			String pwd2=textField_2.getText();
			if (UserService.update2(name, pwd1, pwd2)) {
				JOptionPane.showMessageDialog(null, "修改成功");
				new Mainuser().setVisible(true);
				dispose();
			}else {
				JOptionPane.showMessageDialog(null, "修改失败");
			}
			}
		});
		button.setFont(new Font("宋体", Font.PLAIN, 36));
		button.setBounds(153, 316, 123, 55);
		contentPane.add(button);
		
		JButton button_1 = new JButton("取消");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new Mainuser().setVisible(true);
				dispose();
			}
		});
		button_1.setFont(new Font("宋体", Font.PLAIN, 36));
		button_1.setBounds(429, 316, 123, 55);
		contentPane.add(button_1);
		
		JButton button_2 = new JButton("");
		button_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new Mainuser().setVisible(true);
				dispose();
			}
		});
		button_2.setIcon(new ImageIcon(XGMM.class.getResource("/com/ejia/photo/返回.png")));
		button_2.setBackground(SystemColor.activeCaptionBorder);
		button_2.setBounds(0, 0, 86, 71);
		contentPane.add(button_2);
		setLocationRelativeTo(null);
	}

}
